home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekkan Dennou Club 147
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin
/
docs
/
ippon
/
data
/
oplaser
/
enemy.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-10-25
|
4KB
|
208 lines
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <XSP2lib.H>
#include "boss01.h"
#include "enemy.h"
#include "fxsp2lib.h"
#define enemy_MAX 64 /* 最大数 */
#define R_TOP 1.5*M_PI /* 回転角初期値 */
#define R 12.0 /* 回転長さ */
#define RA 0.01 /* 回転角加速度 */
#define RVMAX 0.1 /* 回転角速度最大値 */
#define RX 8.0 /* 回転中心 x */
#define RY -12.0 /* 回転中心 y */
#define BX -16 /* 本体スプライト座標へのオフセット */
#define BY -24
#define PX -16 /* パーツ回転角からスプライト座標へのオフセット */
#define PY -24
#define SEQ_1 22 /* ばね振動開始時間 */
#define SPRING_TOP_Y -2.0 /* ばね振動 y 初期値 */
#define SPRING_K 0.5 /* ばね定数 */
#define SPRING_M 0.70 /* ばね振動摩擦計数 */
ENEMY *enemy, *enemy_top, *enemy_null_top;
int enemy_init0 (void)
{
int i;
if ((enemy = malloc (sizeof (enemy) * enemy_MAX)) == NULL)
return (-1);
enemy_top = NULL;
enemy_null_top = enemy;
for (i = 0; i < enemy_MAX; i++) {
enemy[i].next = &enemy[i + 1];
}
enemy[enemy_MAX - 1].next = NULL;
return (0);
}
void enemy_init (short type, short pt, short info, short ox, short oy)
{
if (enemy_null_top != NULL) {
ENEMY *p;
p = enemy_null_top;
enemy_null_top = p->next;
p->next = enemy_top;
enemy_top = p;
p->type = type;
p->pt = pt;
p->info = info;
p->ox = ox;
p->oy = oy;
switch (type) {
case 0: /* 本体 */
case 1:
case 2:
case 3: /* 本体 */
case 4:
case 5:
break;
case 10: /* 可動部(右) */
case 11:
case 12:
case 13:
case 14:
case 15:
p->round = R_TOP;
p->round_v = 0.0;
p->spring_y = 0.0;
p->spring_v = 0.0;
break;
case 20: /* 可動部(左) */
case 21:
case 22:
case 23:
case 24:
case 25:
p->round = 1.5 * M_PI - (R_TOP - 1.5 * M_PI);
p->round_v = 0.0;
p->spring_y = 0.0;
p->spring_v = 0.0;
break;
default:
break;
}
}
}
void enemy_move (void)
{
ENEMY *p, *q;
p = enemy_top;
q = NULL;
while (p != NULL) {
char erase_flag = 0;
switch (p->type) {
case 0: /* 本体 */
case 1:
case 2:
case 3: /* 本体 */
case 4:
case 5:
p->x = (short) p->ox + BX + 144;
p->y = (short) p->oy + BY + 144;
xsp_set_st (p);
fxsp_set_st (p);
break;
case 10: /* 可動部(右) */
case 11:
case 12:
case 13:
case 14:
case 15:
if (seq_counter == SEQ_1)
p->spring_y = SPRING_TOP_Y;
if (seq_counter < SEQ_1) {
p->round += p->round_v;
if ((p->round_v += RA) > RVMAX)
p->round_v = RVMAX;
} else {
p->spring_y += p->spring_v;
p->spring_v -= SPRING_K * p->spring_y;
p->spring_v *= SPRING_M;
}
p->x = R * cos (p->round) + RX + PX + p->ox + 144;
p->y = -R * sin (p->round) + RY + PY + p->spring_y + p->oy + 144;
xsp_set_st (p);
fxsp_set_st (p);
break;
case 20: /* 可動部(左) */
case 21:
case 22:
case 23:
case 24:
case 25:
if (seq_counter == SEQ_1)
p->spring_y = SPRING_TOP_Y;
if (seq_counter < SEQ_1) {
p->round += p->round_v;
if ((p->round_v -= RA) < -RVMAX)
p->round_v = -RVMAX;
} else {
p->spring_y += p->spring_v;
p->spring_v -= SPRING_K * p->spring_y;
p->spring_v *= SPRING_M;
}
p->x = R * cos (p->round) - RX - (32 + PX) + p->ox + 144;
p->y = -R * sin (p->round) + RY + PY + p->spring_y + p->oy + 144;
xsp_set_st (p);
fxsp_set_st (p);
break;
}
if (erase_flag) {
if (q == NULL) { /* リストの一番最初を削除 */
enemy_top = p->next;
p->next = enemy_null_top;
enemy_null_top = p;
q = NULL;
p = enemy_top;
} else {
q->next = p->next;
p->next = enemy_null_top;
enemy_null_top = p;
p = q->next;
}
} else {
q = p;
p = p->next;
}
}
}
void enemy_tini (void)
{
int i;
enemy_top = NULL;
enemy_null_top = enemy;
for (i = 0; i < enemy_MAX; i++) {
enemy[i].next = &enemy[i + 1];
}
enemy[enemy_MAX - 1].next = NULL;
}